package com.kingtone.rongji.tool;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.MyLocationData;

public class LocationService extends Service
{
	private LocationClient mLocationClient = null;
	public static MyLocationData locData;

	public void onCreate()
	{
		super.onCreate();
	}

	public BDLocationListener myLocationListener = new BDLocationListener()
	{
		@Override
		public void onReceiveLocation(BDLocation location) {
			if (location == null)
				return;
			locData = new MyLocationData.Builder()
					.accuracy(location.getRadius())
					.direction(100).latitude(location.getLatitude())
					.longitude(location.getLongitude()).build();
			mLocationClient.stop();
		}
		
		public void onReceivePoi(BDLocation location)
		{
		}
	};

	public int onStartCommand(Intent paramIntent, int paramInt1, int paramInt2)
	{
		startLocation();
		return super.onStartCommand(paramIntent, paramInt1, paramInt2);
	}

	public void startLocation()
	{
		mLocationClient = new LocationClient(this);
		mLocationClient.registerLocationListener(this.myLocationListener);
		LocationClientOption localLocationClientOption = new LocationClientOption();
		localLocationClientOption.setOpenGps(true);
		localLocationClientOption.setCoorType("bd09ll");
		localLocationClientOption.setScanSpan(5000);
		localLocationClientOption.setPriority(LocationClientOption.NetWorkFirst);
		mLocationClient.setLocOption(localLocationClientOption);
		mLocationClient.start();
	}

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onDestroy() {
		mLocationClient.stop();
		super.onDestroy();
	}
}
